# -*- coding: utf-8 -*-
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from datetime import timedelta
from jms.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms.dwd.dwd_warhouse.dwd_wide_unsign_summary_waybill_dt import jms_dwd__dwd_wide_unsign_summary_waybill_dt
from jms.dwd.dwd_wide_abnormal_detail_waybill_dt import jms_dwd__dwd_wide_abnormal_detail_waybill_dt
from jms.dwd.tab.dwd_tab_barscan_difficult_base_dt import jms_dwd__dwd_tab_barscan_difficult_base_dt
from jms.dwd.tab.dwd_tab_barscan_centerarrival_base_dt import jms_dwd__dwd_tab_barscan_centerarrival_base_dt
from jms.dwd.tab.dwd_tab_barscan_unloading_base_dt import jms_dwd__dwd_tab_barscan_unloading_base_dt
from jms.dwd.tab.dwd_tab_barscan_send_base_dt import jms_dwd__dwd_tab_barscan_send_base_dt
from jms.dwd.tab.dwd_tab_barscan_loading_base_dt import jms_dwd__dwd_tab_barscan_loading_base_dt
from jms.dwd.oms.dwd_yl_oms_interceptorpiece_base import jms_dwd__dwd_yl_oms_interceptorpiece_base
from jms.dwd.tab.dwd_tab_reback_transfer_express_base import jms_dwd__dwd_tab_reback_transfer_express_base
from jms.dwd.tab.dwd_tab_report_errorbagging_detail_dt import jms_dwd__dwd_tab_report_errorbagging_detail_dt
from jms.dm.dm_missing_bind import jms_dm__dm_missing_bind_dt
from jms.dwd.oms.dwd_oms_order_dt import jms_dwd__dwd_oms_order_dt
from jms.dim.dim_first_second_third_code_info import jms_dim__dim_first_second_third_code_info
from jms.dim.dim_tab_bulk_cargo_shift_base import jms_dim__dim_tab_bulk_cargo_shift_base
from jms.dwd.tab.dwd_tab_barscan_centersend_base_dt import jms_dwd__dwd_tab_barscan_centersend_base_dt
from jms.dwd.tms.dwd_tmsnew_shipment_stop_union_base_dt import jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt
from jms.dwd.tms.dwd_tmsnew_shipment_union_base_dt import jms_dwd__dwd_tmsnew_shipment_union_base_dt
from jms.dim.dim_tmsnew_vehicle_line import jms_dim__dim_tmsnew_vehicle_line
from jms.dim.tms.dim_yl_tms_vehicle_type_base import jms_dim__dim_yl_tms_vehicle_type_base
from jms.time_sensor.time_after_05_00 import time_after_04_45

jms_dm__dm_centersend_timerate_all_detail_v2_dt = SparkSqlOperator(
    task_id='jms_dm__dm_centersend_timerate_all_detail_v2_dt',
    task_concurrency=1,
    pool_slots=5,
    master='yarn',
    #execution_timeout=timedelta(hours=2)
    #excel平均时长:0
    execution_timeout = timedelta(minutes=60),
    email=['wangmenglei@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_centersend_timerate_all_detail_v2_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dm/dm_centersend_timerate_all_detail_v2_dt/execute.sql',
    driver_memory='16G',
    driver_cores=8,
    executor_memory='18G',
    executor_cores=6,
    num_executors=80,
    retries=0,
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 100,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '6G',  # 堆外内存
          'spark.default.paralleism': 1500,
          'spark.sql.shuffle.partitions': 1500,
          'spark.shuffle.file.buffer':'64K',
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=6'
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': 200,
              'hive.exec.max.dynamic.partitions': 200
              },
)

jms_dm__dm_centersend_timerate_all_detail_v2_dt << [
    jms_dim__dim_network_whole_massage,
    jms_dwd__dwd_wide_unsign_summary_waybill_dt,
    jms_dwd__dwd_wide_abnormal_detail_waybill_dt,
    jms_dwd__dwd_tab_barscan_difficult_base_dt,
    jms_dwd__dwd_tab_barscan_centerarrival_base_dt,
    jms_dwd__dwd_tab_barscan_unloading_base_dt,
    jms_dwd__dwd_tab_barscan_send_base_dt,
    jms_dwd__dwd_tab_barscan_loading_base_dt,
    jms_dwd__dwd_yl_oms_interceptorpiece_base,
    jms_dwd__dwd_tab_reback_transfer_express_base,
    jms_dwd__dwd_tab_report_errorbagging_detail_dt,
    jms_dm__dm_missing_bind_dt,
    jms_dwd__dwd_oms_order_dt,
    jms_dim__dim_first_second_third_code_info,
    jms_dim__dim_tab_bulk_cargo_shift_base,
    jms_dwd__dwd_tab_barscan_centersend_base_dt,
    jms_dwd__dwd_tmsnew_shipment_stop_union_base_dt,
    jms_dwd__dwd_tmsnew_shipment_union_base_dt,
    jms_dim__dim_tmsnew_vehicle_line,
    jms_dim__dim_yl_tms_vehicle_type_base,
    time_after_04_45
]